//
// Created on 2023/7/5.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#ifndef DATA_PARSER_H
#define DATA_PARSER_H

#include "hid_simulator.h"

#define MAX_KEY_NUM 2

class DataParser {
  public:
    DataParser() = default;

    virtual ~DataParser() = default;

    static DataParser &GetInstance();

    // 解析数据
    virtual int32_t ParseData(const uint8_t *buffer, uint32_t length);

    // 设置keycode map
    void UpdateKeyCodeMap(int keyIndex, int keyValue);

    // 开启EmitEvent
    void StartWork();

  private:
    int32_t ParseKeyData(const uint8_t *buffer);

    int32_t ParseMoveData(const uint8_t *buffer);
    
    bool isZero(const uint8_t *buffer, uint32_t length);
    
  private:
    EventData eventData_;
    EventData lastData_;
    int keyCodeMap_[MAX_KEY_NUM];
    HidSimulator simulator_;
};

#endif // DATA_PARSER_H
